<?php

require_once 'BasicController.php';
require_once '../application/business/AddressBusiness.php';

class AddressController extends Zend_Controller_Action
{

	public function init()
	{
	}

	public function indexAction()
	{
		// action body
	}

	//RECUPERA O ENDEREÇO A PARTIR DO CEP INFORMADO
	public function getAddressAction(){
		$this->_helper->layout->disableLayout();

		$cep = $this->getRequest()->getParam("cep");

		$addressBusiness = new AddressBusiness();

		$result = $addressBusiness->getAddressByCep(str_replace("-","",$cep));

		if($result){
			$address = array(
				'address' 		=>	$texto = utf8_encode($result['address']),
				'address_type' 	=>	$texto = utf8_encode($result['description']),
				'city' 			=>	$texto = utf8_encode($result['des_city']),
				'neighborhood'	=>	$texto = utf8_encode($result['des_district']),
				'state'			=>	$texto = utf8_encode($result['des_state'])
			);
			$myJSON = json_encode($address);
		}else{
			$myJSON = null;
		}

		echo $myJSON ;
	}

	//RECUPERA TODAS AS CIDADES PARA UM DETERMINADO ESTADO
	public function getCitiesAction(){

		$this->_helper->layout->disableLayout();

		$state = $this->getRequest()->getParam("state");

		$addressBusiness = new AddressBusiness();

		$this->view->cities = $addressBusiness->getCityByState($state);


	}

}